package cn.chiship.framework.third.biz.wxpub.controller;


import cn.chiship.framework.common.annotation.SystemOptionAnnotation;
import cn.chiship.framework.common.constants.CommonConstants;
import cn.chiship.sdk.framework.base.BaseService;
import cn.chiship.sdk.framework.base.BaseController;
import cn.chiship.sdk.core.base.BaseResult;
import cn.chiship.sdk.core.annotation.Authorization;

import javax.annotation.Resource;

import cn.chiship.framework.third.biz.wxpub.service.ThirdWechatUserLocationService;
import cn.chiship.framework.third.biz.wxpub.entity.ThirdWechatUserLocation;
import cn.chiship.framework.third.biz.wxpub.entity.ThirdWechatUserLocationExample;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 微信用户实时坐标控制层
 * 2022/9/18
 *
 * @author lijian
 */
@RestController
@Authorization
@RequestMapping("/thirdWechatUserLocation")
@Api(tags = "微信用户实时坐标")
public class ThirdWechatUserLocationController extends BaseController<ThirdWechatUserLocation, ThirdWechatUserLocationExample> {

    private static final Logger LOGGER = LoggerFactory.getLogger(ThirdWechatUserLocationController.class);

    @Resource
    private ThirdWechatUserLocationService thirdWechatUserLocationService;

    @Override
    public BaseService getService() {
        return thirdWechatUserLocationService;
    }

    /**
     * 获取微信用户的地址
     */
    @SystemOptionAnnotation(describe = "获取微信用户地址", systemName = CommonConstants.SYSTEM_NAME_WECHAT)
    @ApiOperation(value = "获取微信用户地址", notes = "获取微信用户地址")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "微信用户id", defaultValue = "", required = false,dataTypeClass =String.class, paramType = "query"),
            @ApiImplicitParam(name = "appId", value = "公众号", defaultValue = "", required = true,dataTypeClass =String.class, paramType = "query")})
    @GetMapping("getWechatUserLocation")
    public ResponseEntity<BaseResult> getWechatUserLocation(@RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "openId", required = true) String openId) {
        ThirdWechatUserLocation wechatUserLocation = null;
        ThirdWechatUserLocationExample wechatUserLocationExample = new ThirdWechatUserLocationExample();
        wechatUserLocationExample.createCriteria().andAppIdEqualTo(appId).andOpenIdEqualTo(openId);
        List<ThirdWechatUserLocation> wechatUserLocationList = thirdWechatUserLocationService.selectByExample(wechatUserLocationExample);
        if (!wechatUserLocationList.isEmpty()) {
            wechatUserLocation = wechatUserLocationList.get(0);
        }
        return super.responseEntity(BaseResult.ok(wechatUserLocation));
    }
}